package com.example.bigwork;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class Shopdetail extends AppCompatActivity {


    private ImageView imageView;
    private TextView txTital;
    private TextView txName;
    private TextView txDetail;
    private TextView txPrice;


    private Button btnBuy;
    private Shop shop;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopdetail);

        //获取控件
        getViews();

        //获取Intent对象
        Intent detail = getIntent();
        //获取intent里面的bundle对象
        Bundle bundle = detail.getBundleExtra("obj");
        //获取bubble里面的数据
        shop = (Shop) bundle.getSerializable("shop");
        //显示数据到对应控件
        showViews();




        //点击购买跳转到购物车
        btnBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(
                        Shopdetail.this,
                        CartActivity.class
                );

                //封装数据
                Bundle bundle = new Bundle();
                bundle.putSerializable("shop", shop);


                //将bundle对象添加到intent中
                intent.putExtra("obj",bundle);



                startActivity(intent);

            }
        });











    }

    private void showViews() {
        imageView.setImageResource(shop.getsImage());
        txName.setText(shop.getsDetail());
        txDetail.setText(shop.getsSafe());
        txPrice.setText(shop.getsPrice());

    }

    private void getViews() {
        imageView = findViewById(R.id.if_image);
        txName = findViewById(R.id.if_name);
        txDetail = findViewById(R.id.if_detail);
        txPrice = findViewById(R.id.if_price);
        btnBuy = findViewById(R.id.btn_buy);
    }
}